function create_hiddin_form(data,action,target){
	$('#hiddenForm').remove();
	var form = $('<form></form>');
	form.attr('id','hiddenForm');
	form.attr('method','post');
	form.attr('action',action);
	form.attr('target',target);
	
	for(var x in data){
		var input = "<input type='hidden' name='"+x+"' value='"+data[x]+"' />";
		form.append(input);
	}
 
	$('body').append(form);
	
	return $('#hiddenForm');
}

function createNewFolder(){
	var data = {system_flag:"createNewFolder",folderName:"NewFolder"};
	var fun = function (j){
		if(j){
			do_refresh();
		}
	}
	$.post('actions.php',data,fun,'json'); 
} 

function orderList(me){
	var value = $(me).val();
	var url = 'main.php?order='+value;
	 
	location.href = url;
}

function editFile(me,type){
	var object = $(me).parent().parent().find('td').eq(1); 
	if(type){
		object = $(me).parent().parent().find('div').eq(1);
		
	}
	var file = object.text(); 
	var input = $("<input  name='fileName' value='"+file+"'  onblur=\"blurActive(this,'"+file+"')\"/>");
	if(type){
		 input.css('width','130px');
		
	}
	object.html(input); 
	input.focus();	
}
 
function blurActive(me,file){  
	var newName = $(me).val();
	var data = {system_flag:"editFile",name:file,newName:newName};
	var fun = function (j){
		if(j == 1){
			do_refresh();
		}else if(j == 2){
			alert('请输入文件的扩展名');
		}else if(j == 3){
			alert('文件的扩展名输入错误');
		}else if(j == 4){
			alert('文件名已存在，请重新命名');
		}else if(j == 5){
			alert('文件名修改失败');
		}
	}
	$.post('actions.php',data,fun,'json'); 
}

function confirmAlert(lab){
	var a = confirm(lab);
	alert(a);	
}
function deleteFile(me,type){ 
	b = '您确定要删除吗？'; 
	if(!confirm(b)){
		return ;
	}
	
	var object = $(me).parent().parent().find('td').eq(1);
	if(type){
		object = $(me).parent().parent().find('div').eq(1);
		
	}
	var file = object.text();
	
	var data = {system_flag:"deleteFile",name:file};
	var fun = function (j){
		if(j){
			do_refresh();
		}else {
			alert('文件名删除失败');
		}
	}
	$.post('actions.php',data,fun,'json');  
}

function enterIn(folder){ 
	var data = {EXPLORER_FOLDER:folder};
	form = create_hiddin_form(data,location.href,'');
	form.submit(); 
}

function chooseFile(name,fullPath,formate){
	try{
		parent.closeOpen();
		parent.returnFile(name,fullPath,formate);
	}catch(e){
		//
	}
}

function chooseAttachment(name,size,id){
	try{
		parent.returnAttachment(name,size,id);
			
	}catch(e){
		//
	}
}

var types = ["php","php3","php4","php5","asp","aspx","js","exe","json","py","jsp","pl"];


function submitRename2(){
	return checkTypeError();
}

function submitRename(me){
	if(checkTypeError()){
		me.form.submit();
	}
}

function checkTypeError(){
	var me = document.getElementById("new_name") ;

	if(me.value == ""){
		alert(label("common.file_name_empty"));
		return false ;
	}
	for(var i=0;i<types.length;i++){
		var t = types[i];
		if(me.value.indexOf(t) >= 0){
			alert(label("common.file_type_error"));
			return false;
		}
	}
	return true ;
}

function previewFile(icon){
	$("#col_file_preview").css("background-image","url("+icon+")");
}

function choosed_file(src){
	parent.get_file(src);
}

function get_read_type(me){
	var type = $(me).val(); 
	var data = {view_type:type};
	
	form = create_hiddin_form(data,location.href,'');
	form.submit(); 
}